package com.jhgsys.internal.accident.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jhgsys.internal.accident.constant.AccidentConstant;
import com.jhgsys.internal.accident.dto.*;
import com.jhgsys.internal.accident.entity.*;
import com.jhgsys.internal.accident.mapper.AccidentReportMapper;
import com.jhgsys.internal.accident.service.*;
import com.jhgsys.internal.common.constant.DictCodeConstant;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.BeanHelper;
import com.jhgsys.internal.common.utils.DateUtil;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.dict.entity.DictItem;
import com.jhgsys.internal.dict.service.IDictService;
import com.jhgsys.internal.hazard.entity.AccidentReportSurveyUser;
import com.jhgsys.internal.hazard.service.IAccidentReportSurveyUserService;
import com.jhgsys.internal.system.entity.Dept;
import com.jhgsys.internal.system.entity.Tenant;
import com.jhgsys.internal.system.service.IDeptService;
import com.jhgsys.internal.system.service.ITenantService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Service实现
 *
 * @author admin
 * @date 2024-08-07 16:43:01
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class AccidentReportServiceImpl extends ServiceImpl<AccidentReportMapper, AccidentReport> implements IAccidentReportService {
    @Autowired
    private IDictService dictService;

    @Autowired
    private ITenantService tenantService;

    @Autowired
    private IDeptService deptService;

    @Autowired
    private IAccidentAuditRecordService accidentAuditRecordService;

    @Autowired
    private IAccidentReportInkuryUserService accidentReportInkuryUserService;

    @Autowired
    private IAccidentReportCulpritUserService accidentReportCulpritUserService;

    @Autowired
    private IAccidentReportFileService accidentReportFileService;

    @Autowired
    private IAccidentReportReasonFileService accidentReportReasonFileService;

    @Autowired
    private IAccidentReportReasonService accidentReportReasonService;

    @Autowired
    private IAccidentReportRectificationService accidentReportRectificationService;

    @Autowired
    private IAccidentReportSurveyUserService accidentReportSurveyUserService;

    @Autowired
    private IAccidentReportTimelineService accidentReportTimelineService;


    /**
     * 查询（分页）
     *
     * @param request        QueryRequest
     * @param accidentReport accidentReport
     * @return IPage<AccidentReport>
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    public IPage<AccidentReportDto> findAccidentReports(QueryRequest request, AccidentReportDto accidentReport) {
        IPage<AccidentReportDto> result = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<AccidentReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AccidentReport::getDeletedFlg, FebsConstant.VALID);
        if (StringUtils.isNotBlank(accidentReport.getTenantId())) {
            queryWrapper.eq(AccidentReport::getTenantId, accidentReport.getTenantId());
        }

        if (StringUtils.isNotBlank(accidentReport.getBusinessType())) {
            switch (accidentReport.getBusinessType()) {
                case "accidentReport":
                    //事故上报人
                    if (StringUtils.isNotBlank(accidentReport.getCreatedBy())) {
                        queryWrapper.eq(AccidentReport::getCreatedBy, accidentReport.getCreatedBy());
                    }
                    if (StringUtils.isNotBlank(accidentReport.getStatus())) {
                        switch (accidentReport.getStatus()) {
                            case "1":
                                queryWrapper.eq(AccidentReport::getStatus, "1");
                                break;
                            case "2":
                                queryWrapper.eq(AccidentReport::getStatus, "2");
                                queryWrapper.eq(AccidentReport::getSurveyStatus, "1");
                                break;
                            case "3":
                                queryWrapper.eq(AccidentReport::getStatus, "2");
                                queryWrapper.eq(AccidentReport::getSurveyStatus, "2");
                                break;
                            case "4":
                                queryWrapper.eq(AccidentReport::getStatus, "2");
                                queryWrapper.eq(AccidentReport::getSurveyStatus, "3");
                                break;
                            case "5":
                                queryWrapper.eq(AccidentReport::getStatus, "2");
                                queryWrapper.eq(AccidentReport::getSurveyStatus, "4");
                                break;
                            case "6":
                                queryWrapper.eq(AccidentReport::getStatus, "2");
                                queryWrapper.eq(AccidentReport::getSurveyStatus, "5");
                                break;
                            case "7":
                                queryWrapper.eq(AccidentReport::getStatus, "2");
                                queryWrapper.eq(AccidentReport::getSurveyStatus, "6");
                                break;
                            case "8":
                                queryWrapper.eq(AccidentReport::getStatus, "3");
                                break;
                        }
                    }
                    break;
                case "surveyAudit":
                    //事故调查审核
                    queryWrapper.eq(AccidentReport::getSurveyStatus, AccidentConstant.ACCIDENT_SURVEYED_FOR_AUDIT);
                    //责任人部门
                    if(StringUtils.isNotBlank(accidentReport.getObligationDeptId())){
                        queryWrapper.eq(AccidentReport::getObligationDeptId, accidentReport.getObligationDeptId());
                    }
                    //责任人
                    if(StringUtils.isNotBlank(accidentReport.getObligationUserId())){
                        queryWrapper.eq(AccidentReport::getObligationUserId, accidentReport.getObligationUserId());
                    }
                    break;
            }
        }
        if (StringUtils.isNotBlank(accidentReport.getAccidentNo())) {
            queryWrapper.like(AccidentReport::getAccidentNo, accidentReport.getAccidentNo());
        }
        if (StringUtils.isNotBlank(accidentReport.getAccidentTitle())) {
            queryWrapper.like(AccidentReport::getAccidentTitle, accidentReport.getAccidentTitle());
        }
        if (StringUtils.isNotBlank(accidentReport.getAccidentType())) {
            queryWrapper.eq(AccidentReport::getAccidentType, accidentReport.getAccidentType());
        }
        if (StringUtils.isNotBlank(accidentReport.getAccidentLevel())) {
            queryWrapper.eq(AccidentReport::getAccidentLevel, accidentReport.getAccidentLevel());
        }

        if (StringUtils.isNotBlank(accidentReport.getSurveyStatus())) {
            queryWrapper.eq(AccidentReport::getSurveyStatus, accidentReport.getSurveyStatus());
        }
        if (StringUtils.isNotBlank(accidentReport.getStartDate()) && StringUtils.isNotBlank(accidentReport.getEndDate())) {
            Date startDate = DateUtil.parseDate(accidentReport.getStartDate(), DateUtil.FULL_TIME_SPLIT_PATTERN);
            Date endDate = DateUtil.parseDate(accidentReport.getEndDate(), DateUtil.FULL_TIME_SPLIT_PATTERN);
            queryWrapper.between(AccidentReport::getAccidentDate, startDate, endDate);
        }
        queryWrapper.orderByDesc(AccidentReport::getCreatedTime);
        Page<AccidentReport> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        IPage<AccidentReport> pages = this.page(page, queryWrapper);

        List<AccidentReport> reportList = pages.getRecords();
        List<AccidentReportDto> dtoList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(reportList)) {
            dtoList = BeanHelper.copyWithCollection(reportList, AccidentReportDto.class);
        }

        dtoList.forEach(p -> {
            Tenant tenant = tenantService.findTenantByTenantId(p.getTenantId());
            p.setTenantName(Optional.ofNullable(tenant).map(Tenant::getTenantName).orElse(""));
        });
        result.setRecords(dtoList);
        result.setTotal(dtoList.size());
        return result;
    }

    /**
     * 调查录入 以AccidentReport为主表查询（所有）
     *
     * @param accidentReportDto accidentReportDto
     * @return List<AccidentReportDto>
     * @author admin
     * @date 2024-08-20 15:49:12
     */
    @Override
    public Map<String, Object> findAccidentReportsBySql(AccidentReportDto accidentReportDto) {
        Map<String, Object> result = new HashMap<>();
        List<AccidentReportDto> list = this.baseMapper.findAccidentReportsBySql(accidentReportDto);
        result.put("rows", list);
        result.put("total", list.size());
        return result;
    }

    /**
     * 调查录入 以AccidentReport为主表查询（所有）
     *
     * @param accidentReportDto accidentReportDto
     * @return List<AccidentReportDto>
     * @author admin
     * @date 2024-08-20 15:49:12
     */
    @Override
    public Map<String, Object> findAccidentReportsAll(AccidentReportDto accidentReportDto) {
        Map<String, Object> result = new HashMap<>();
        List<AccidentReportDto> list = this.baseMapper.findAll(accidentReportDto);
//        if(CollectionUtils.isNotEmpty(list)){
//            list.forEach(d ->{
//                if(CollectionUtils.isNotEmpty(d.getChildren())){
//                    d.setIsParent(true);
//                }else{
//                    d.setIsParent(false);
//                }
//            });
//        }
        result.put("code", "0");
        result.put("data", list);
        result.put("count", list.size());
        return result;
    }

    /**
     * 整改查询（分页）
     *
     * @param request        QueryRequest
     * @param accidentReport accidentReport
     * @return rectifyList
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    public IPage<Map<String, Object>> rectifyList(QueryRequest request, AccidentReportDto accidentReport) {
        IPage<Map<String, Object>> resultPage = new Page<>();
        List<Map<String, Object>> tableData = new ArrayList<>();
        IPage<AccidentReportRectificationDto> page = accidentReportRectificationService.findPageByReport(request, accidentReport);
        List<AccidentReportRectificationDto> records = page.getRecords();
        records.forEach(item -> {
            Map<String, Object> rowData = new HashedMap();
            rowData = BeanMap.create(item);
            tableData.add(rowData);
        });
        resultPage.setRecords(tableData);
        resultPage.setTotal(page.getTotal());
        return resultPage;
    }

    /**
     * 查询（所有）
     *
     * @param accidentReport accidentReport
     * @return List<AccidentReport>
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    public List<AccidentReport> findAccidentReports(AccidentReport accidentReport) {
        LambdaQueryWrapper<AccidentReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AccidentReport::getDeletedFlg, FebsConstant.VALID);
        // TODO 设置查询条件

        return this.baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID查询
     *
     * @param id
     * @return AccidentReport
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    public AccidentReportDto findAccidentReportById(String id) {
        AccidentReport accidentReport = this.baseMapper.selectById(id);
        if (null != accidentReport) {
            AccidentReportDto accidentReportDto = BeanHelper.copyProperties(accidentReport, AccidentReportDto.class);
            //查询事故伤亡人员
            accidentReportDto.setInjuryUserDataList(accidentReportInkuryUserService.list(new LambdaQueryWrapper<AccidentReportInkuryUser>().eq(AccidentReportInkuryUser::getReportId, accidentReportDto.getReportId())));
            //查询事故肇事人员
            accidentReportDto.setCulpritUserDataList(accidentReportCulpritUserService.list(new LambdaQueryWrapper<AccidentReportCulpritUser>().eq(AccidentReportCulpritUser::getReportId, accidentReportDto.getReportId())));
            //查询事故时间线
            accidentReportDto.setTimelineList(accidentReportTimelineService.list(new LambdaQueryWrapper<AccidentReportTimeline>().eq(AccidentReportTimeline::getReportId, accidentReportDto.getReportId())));
            //事故上报附件
            accidentReportDto.setAccidentReportFileList(accidentReportFileService.list(new LambdaQueryWrapper<AccidentReportFile>()
                    .eq(AccidentReportFile::getReportId, accidentReportDto.getReportId())
                    .eq(AccidentReportFile::getReportFileType, "1")
            ));
            // 调查人员
            AccidentReportSurveyUser accidentReportSurveyUser = new AccidentReportSurveyUser();
            accidentReportSurveyUser.setReportId(id);
            List<AccidentReportSurveyUser> accidentReportSurveyUserList = accidentReportSurveyUserService.findAccidentReportSurveyUserList(accidentReportSurveyUser);
            Map<String, List<AccidentReportSurveyUser>> groupMap = accidentReportSurveyUserList.stream().collect(Collectors.groupingBy(AccidentReportSurveyUser::getDutyName));
            List<AccidentSurveyUserDto> accidentSurveyUserDtoList = new ArrayList<>();
            for (String dutyName : groupMap.keySet()) {
                AccidentSurveyUserDto accidentSurveyUserDto = new AccidentSurveyUserDto();
                accidentSurveyUserDto.setDutyName(dutyName);
                accidentSurveyUserDto.setSurveyUserList(groupMap.get(dutyName));
                accidentSurveyUserDtoList.add(accidentSurveyUserDto);
            }
            accidentReportDto.setTeamList(accidentSurveyUserDtoList);

            //事故分析图
            accidentReportDto.setReportAnalysisFileList(accidentReportFileService.list(new LambdaQueryWrapper<AccidentReportFile>()
                    .eq(AccidentReportFile::getReportId, accidentReportDto.getReportId())
                    .eq(AccidentReportFile::getReportFileType, "3")
            ));
            //事故图解
            accidentReportDto.setReportImgFileList(accidentReportFileService.list(new LambdaQueryWrapper<AccidentReportFile>()
                    .eq(AccidentReportFile::getReportId, accidentReportDto.getReportId())
                    .eq(AccidentReportFile::getReportFileType, "2")
            ));
            //事故调查附件
            accidentReportDto.setAccidentSurveyFileList(accidentReportFileService.list(new LambdaQueryWrapper<AccidentReportFile>()
                    .eq(AccidentReportFile::getReportId, accidentReportDto.getReportId())
                    .eq(AccidentReportFile::getReportFileType, "4")
            ));
            //事故整改措施
            List<AccidentReportRectification> list = accidentReportRectificationService.list(new LambdaQueryWrapper<AccidentReportRectification>()
                    .eq(AccidentReportRectification::getReportId, accidentReportDto.getReportId())
            );
            accidentReportDto.setRectificationOpinionList(list);

            return accidentReportDto;
        }
        return new AccidentReportDto();
    }

    /**
     * 新增
     *
     * @param accidentReport accidentReport
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    @Transactional
    public void createAccidentReport(AccidentReport accidentReport) {
        accidentReport.setCreatedTime(new Date());
        this.save(accidentReport);
    }

    /**
     * 修改
     *
     * @param accidentReportDto accidentReportDto
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    @Transactional
    public void updateAccidentReport(AccidentReportDto accidentReportDto) {
        AccidentReport accidentReport = BeanHelper.copyProperties(accidentReportDto, AccidentReport.class);
        this.saveOrUpdate(accidentReport);
    }

    /**
     * 保存审核信息
     *
     * @param accidentReportDto accidentReportDto
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    @Transactional
    public void saveAccidentAuditRecord(AccidentReportDto accidentReportDto) {
        AccidentAuditRecord accidentAuditRecord = new AccidentAuditRecord();
        accidentAuditRecord.setTenantId(accidentReportDto.getTenantId());
        accidentAuditRecord.setReportId(accidentReportDto.getReportId());
        accidentAuditRecord.setCreatedTime(new Date());
        accidentAuditRecord.setCreatedBy(accidentReportDto.getUserId());
        accidentAuditRecord.setAuditUserId(accidentReportDto.getUserId());
        accidentAuditRecord.setAuditRealName(accidentReportDto.getUserRealName());
        accidentAuditRecord.setAuditBusiness(accidentReportDto.getAuditBusiness());
        accidentAuditRecord.setAuditTime(new Date());
        accidentAuditRecord.setAuditResult(accidentReportDto.getAuditResult());
//        if("1".equals(accidentReportDto.getAuditBusiness())){
//            //调查审核备注
//            accidentAuditRecord.setAuditReason(accidentReportDto.getSurveyAuditRemark());
//        }else if("2".equals(accidentReportDto.getAuditBusiness())){
//            //整改审核备注
//            accidentAuditRecord.setAuditReason(accidentReportDto.getRectificationAuditRemark());
//        }
        accidentAuditRecordService.save(accidentAuditRecord);
    }

    /**
     * 逻辑删除
     *
     * @param accidentReport    accidentReport
     * @param accidentReportIds accidentReportIds
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    @Transactional
    public void deleteAccidentReport(AccidentReport accidentReport, String accidentReportIds) {
        List<String> list = Arrays.asList(accidentReportIds.split(StringPool.COMMA));
        this.baseMapper.update(accidentReport, new LambdaQueryWrapper<AccidentReport>().in(AccidentReport::getReportId, list));
    }

    /**
     * 上报重工
     *
     * @param accidentReport    accidentReport
     * @param accidentReportIds accidentReportIds
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    @Transactional
    public void noticeChic(AccidentReport accidentReport, String accidentReportIds) {
        List<String> list = Arrays.asList(accidentReportIds.split(StringPool.COMMA));
        this.baseMapper.update(accidentReport, new LambdaQueryWrapper<AccidentReport>().in(AccidentReport::getReportId, list));
    }

    /**
     * 物理删除
     *
     * @param accidentReportIds accidentReportIds
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    @Transactional
    public void physicallyDeleteAccidentReport(String accidentReportIds) {
        List<String> list = Arrays.asList(accidentReportIds.split(StringPool.COMMA));
        LambdaQueryWrapper<AccidentReport> wapper = new LambdaQueryWrapper<>();
        wapper.in(AccidentReport::getReportId, list);
        this.remove(wapper);
    }

    /**
     * 生成事故编号 公司的业务编码+部门的业务编码+两位年分+序列号（5位）
     *
     * @param tenantId 公司ID
     * @author admin
     * @date 2024-08-07 16:43:01
     */
    @Override
    @Transactional(isolation = Isolation.READ_COMMITTED)
    public String createAccidentNo(String tenantId, String deptId) throws FebsException {
        StringBuilder accidentNo = new StringBuilder();
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        Tenant tenant = tenantService.getById(tenantId);
        if (null == tenant || StringUtils.isBlank(tenant.getTenantCode())) {
            throw new FebsException("事故编号生成异常");
        } else {
            //公司业务编码
            if (StringUtils.isNotBlank(tenant.getBusinessCode())) {
                accidentNo.append(tenant.getBusinessCode());
            }
        }
        Dept dept = deptService.findDeptByDeptId(deptId);
        if (ObjectUtils.isNotEmpty(dept) && StringUtils.isNotBlank(dept.getBusinessCode())) {
            accidentNo.append(dept.getBusinessCode());
        }
        LambdaQueryWrapper<AccidentReport> queryWrapper = new LambdaQueryWrapper<AccidentReport>();
        queryWrapper.apply("DATE_FORMAT(created_time,'%Y') = DATE_FORMAT(NOW(),'%Y')");
        List<AccidentReport> hazardExamineList = this.baseMapper.selectList(queryWrapper);
        Integer length = hazardExamineList.size();
        accidentNo.append(Calendar.getInstance().get(Calendar.YEAR) % 2000);
        String sequencePrefix = "";
        if (length < 99999) {
            sequencePrefix = String.format("%5d", length + 1).replace(" ", "0");
        } else {
            sequencePrefix = String.format("%8d", length + 1).replace(" ", "0");
        }
        accidentNo.append(sequencePrefix);
        return accidentNo.toString();
    }

    /**
     * 调查指派
     *
     * @param accidentReportDto
     */
    @Override
    @Transactional
    public void updateAndInsertTeam(AccidentReportDto accidentReportDto) {
        AccidentReport accidentReport = new AccidentReport();
        BeanUtils.copyProperties(accidentReportDto,accidentReport);
        this.updateById(accidentReport);
        String reportId = accidentReport.getReportId();
        String createBy = accidentReportDto.getUpdatedBy();
        Date createdTime = new Date();
        List<AccidentSurveyUserDto> teamList = accidentReportDto.getTeamList();
        List<AccidentReportSurveyUser> allUserList = new ArrayList<>();
        for (AccidentSurveyUserDto accidentSurveyUserDto : teamList) {
            String dutyName = accidentSurveyUserDto.getDutyName();
            List<AccidentReportSurveyUser> accidentReportSurveyUserList = accidentSurveyUserDto.getTeamUserList().stream().map(item -> {
                AccidentReportSurveyUser accidentReportSurveyUser = new AccidentReportSurveyUser();
                accidentReportSurveyUser.setTenantId(item.getTenantId());
                accidentReportSurveyUser.setReportId(reportId);
                accidentReportSurveyUser.setDutyName(dutyName);
                accidentReportSurveyUser.setSurveyUserId(item.getUserId());
                accidentReportSurveyUser.setSurveyUserNo(item.getUserNo());
                accidentReportSurveyUser.setSurveyRealName(item.getRealName());
                accidentReportSurveyUser.setSurveyDeptId(item.getUserDeptId());
                accidentReportSurveyUser.setSurveyDeptName(item.getUserDeptName());
                accidentReportSurveyUser.setSurveyPostId(item.getUserPostId());
                accidentReportSurveyUser.setSurveyPostName(item.getUserPostName());
                accidentReportSurveyUser.setCreatedBy(createBy);
                accidentReportSurveyUser.setCreatedTime(createdTime);
                return accidentReportSurveyUser;
            }).collect(Collectors.toList());
            allUserList.addAll(accidentReportSurveyUserList);
        }
        accidentReportSurveyUserService.saveBatch(allUserList);
    }

    /**
     * 设置事故报告字典名称
     *
     * @param accidentReportDto
     */
    private AccidentReportDto setDictNameForAccidentReport(AccidentReportDto accidentReportDto) {
        if (ObjectUtils.isNotNull(accidentReportDto)) {
            List<DictItem> dictItems = new ArrayList<>();

            //设置事故类型名称
            if (StringUtils.isNotBlank(accidentReportDto.getAccidentType())) {
                String[] accidentTypes = accidentReportDto.getAccidentType().split(StringPool.COMMA);
                dictItems = dictService.findDictByItemCodes(DictCodeConstant.SAFETY_ACCIDENT_TYPE, Arrays.asList(accidentTypes));
                if (CollectionUtils.isNotEmpty(dictItems)) {
                    accidentReportDto.setAccidentTypeName(dictItems.stream().map(DictItem::getItemName).collect(Collectors.joining(",")));
                }
            }

            //设置事故等级名称
            if (StringUtils.isNotBlank(accidentReportDto.getAccidentLevel())) {
                String[] accidentLevels = accidentReportDto.getAccidentLevel().split(StringPool.COMMA);
                dictItems = dictService.findDictByItemCodes(DictCodeConstant.SAFETY_ACCIDENT_LEVEL, Arrays.asList(accidentLevels));
                if (CollectionUtils.isNotEmpty(dictItems)) {
                    accidentReportDto.setAccidentLevelName(dictItems.stream().map(DictItem::getItemName).collect(Collectors.joining(",")));
                }
            }

        }
        return accidentReportDto;
    }

}
